//
// Created by xili on 2024/9/4 20:11.
// GO BIG OR GO HOME.
//
#include "leetcode.h"

class Solution {
public:
    vector <string> ans;

    vector <string> generateParenthesis(int n) {
        string cur = "";
        dfs(cur, n, n);
        return ans;
    }

    void dfs(string cur, int l, int r) {
        if (l == 0 && r == 0) {
            ans.push_back(cur);
            return;
        }
        if (l > 0) {
            dfs(cur + '(', l - 1, r);
        }
        if (r > l) {
            dfs(cur + ')', l, r - 1);
        }
    }
};